package model;

import java.util.Vector;

/**
 * Team EBE
 * 
 * OperationImpl.java extends ClassElement and adds a toString and a list of
 * parameters; List of parameters has functionality to add, remove, and clear
 * 
 */
public class OperationImpl extends ClassElement {
	protected Vector<ParameterImpl> parameters;

	public OperationImpl() {
		super();
		parameters = new Vector<ParameterImpl>();
	}

	public OperationImpl(String nameIn, String typeIn, char visIn) {
		super(nameIn, typeIn, visIn);
		parameters = new Vector<ParameterImpl>();
	}

	public void add_parameter(String name, String type) {
		ParameterImpl toAdd = new ParameterImpl();
		toAdd.setName(name);
		toAdd.setType(type);
		parameters.add(toAdd);
		return;
	}

	public void remove_parameter(int index) {
		parameters.remove(index);
		return;
	}

	public void clear() {
		parameters.clear();
	}

	public Vector<ParameterImpl> getParameters() {
		return parameters;
	}

	public String toString() {
		String str = new String();
		str = this.getVisibility() + " " + this.getName() + "(";
		str += ") : " + this.getType();
		return str;
	}

	public String saveString() {

		String s = "<operation>\n<visibility>" + this.getVisibility()
				+ "</visibility>\n<eName>" + this.getName()
				+ "</eName>\n<eType>" + this.getType() + "</eType>\n";
		if (parameters.size() > 0) {
			for (ParameterImpl p : parameters) {
				s += p.xmlString();
			}
		}
		s += "</operation>\n";
		return s;

	}
}
